﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc。@Copy Right 2019
// 文件： Clues.cs
// 项目名称：斑马车务
// 创建时间：2019-12-11
// 负责人：lsc
// ===================================================================
using System;
using System.Data;
using System.Collections.Generic;
using Dapper.Extensions;
using CRM.Infrastructure.Entity;
using CRM.Infrastructure.Repository;
using CRM.Infrastructure.Models;
using CRM.Infrastructure.Dto;

namespace CRM.Infrastructure.Service
{

    /// <summary>
    ///
    /// </summary>
    public class CluesService
    {
        protected CluesRepository repository;

        public CluesService()
        {
            repository = new CluesRepository();
        }

        #region 增删改查

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(Clues entity) { return repository.Insert(entity); }

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(List<Clues> entitys) { return repository.Insert(entitys); }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Update(Clues entity) { return repository.Update(entity); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Delete(Clues entity) { return repository.Delete(entity); }

        /// <summary>
        /// 删除所有
        /// </summary>
        /// <returns></returns>
        public bool DeleteAll() { return repository.DeleteAll(); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public bool Delete(int primaryKey) { return repository.Delete(primaryKey); }

        /// <summary>
        /// 查询单个实体
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public Clues SingleOrDefault(object primaryKey) { return repository.SingleOrDefault(primaryKey); }


        /// <summary>
        /// 查询单个实体,如果存在多条则引发异常
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public Clues Single(object primaryKey) { return repository.Single(primaryKey); }

        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns></returns>
        public List<Clues> QueryAll()
        {
            return repository.QueryAll();
        }

        #endregion

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Page<CluesDto> GetPages(ClueSearchModel model)
        {
            return repository.GetPages(model);
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Page<CluesDto> GetPCPages(ClueSearchPCModel model)
        {
            return repository.GetPCPages(model);
        }

        /// <summary>
        /// 获取未同步
        /// </summary>
        /// <param name="companyID"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List<CluesDto> GetSync(int companyID, int pageSize)
        {
            return repository.GetSync(companyID, pageSize);
        }

        /// <summary>
        /// 更新已经同步
        /// </summary>
        /// <param name="clueIds"></param>
        /// <returns></returns>
        public int UpdateSync(List<CluesDto> clues)
        {
            return repository.UpdateSync(clues);
        }

        /// <summary>
        /// 更新已经同步
        /// </summary>
        /// <param name="clueId"></param>
        /// <returns></returns>
        public int UpdateMessage(int clueId)
        {
            return repository.UpdateMessage(clueId);
        }

        /// <summary>
        /// 获取首页统计
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<int> GetStatistic(long userId, DateTime dt)
        {
            return repository.GetStatistic(userId, dt);
        }

        /// <summary>
        /// 分配线索
        /// </summary>
        /// <param name="model"></param>
        public void AssignUser(AssignUserModel model)
        {
            repository.AssignUser(model);
        }

        /// <summary>
        /// 分配线索
        /// </summary>
        /// <param name="model"></param>
        public void AssignUsers(AssignUsersModel model)
        {
            repository.AssignUsers(model);
        }

        public Clues GetByID(int id)
        {
            return repository.Single(id);
        }
    }

}